
const Ajv = require("ajv")
const ajv = new Ajv() // options can be passed, e.g. {allErrors: true}
// const addFormats = require("ajv-formats")

ajv.addFormat('test', (data) => {
    console.log(data, '============');
    return data === 'haha'
})
const schema = {
    type: "object",
    properties: {
        email: {
            type: "string",
            // format: 'email'
            format: 'test'
        },
        foo: { type: "integer" },
        bar: { type: "string", minLength: 10 },

    },
    required: ["foo"],
    additionalProperties: false
}

const validate = ajv.compile(schema)

const data = {
    email: 'haha',
    foo: 12,
    bar: "abc"
}

const valid = validate(data)
if (!valid) console.log(validate.errors)